<template>
	<div style="margin: 0 20px;">
		<div class="logo">
			<image src="/static/image/logo.png" />
		</div>
		<uni-forms :modelValue="loginForm">
			<!-- 输入账号（用户名） -->
			<uni-forms-item label="账号">
				<uni-easyinput type="text" v-model="loginForm.name" placeholder="请输入账号" />
			</uni-forms-item>
			<!-- 输入密码 -->
			<uni-forms-item label="密码">
				<uni-easyinput type="password" v-model="loginForm.password" placeholder="请输入密码" />
			</uni-forms-item>

			<!-- 登录按钮 -->
			<button style="margin-top: 10px;" type="primary" size="large" @click="onClickLogin">登录</button>


		</uni-forms>
	</div>
</template>

<script>
	export default {

		data() {
			return {
				loginForm: {
					name: "dingding", //用户名，仅仅测试方便
					password: "123456",
				},
				redirectPath: "",
			}
		},

		onLoad() {
			uni.showToast({
				title: "从本地存储提取已将登录的用户名和密码作初始默认显示",
				icon: "success"
			});
			let user = JSON.parse(uni.getStorageSync('user'));
			this.loginForm.name = user.name
			this.loginForm.password = user.password
		},
		methods: {
			onClickLogin() {
				if (this.loginForm.name === "" || this.loginForm.password === "") {
					uni.showToast({ title: "账号或密码不能为空", icon: "error" });
					return;
				}

				//this.loginForm 本地保存用户名和密码
				uni.setStorageSync('user', JSON.stringify(this.loginForm));
				uni.showToast({
					title: "已将登录用户名和密码保存在本地存储了！",
					icon: "success"
				});
			},
		}
	}
</script>

<style>

</style>